package org.particlethink.model;

import org.particlethink.entry.PlanStatus;
import org.particlethink.handler.PlanStatusHandler;
import tk.mybatis.mapper.annotation.ColumnType;
import tk.mybatis.mapper.annotation.KeySql;

import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;

@Table(name = "batch_plans")
public class BatchPlan {//批次计划
    @Id
    @KeySql(useGeneratedKeys = true)
    private Integer id;
    private String no; //单号
    private Date createdAt;
    private Integer projectId;//项目id
    private Integer masterPlanId;//总计划id
    private String masterPlanNo;//总计划单号
    private Date deadlineAt;//最晚进场时间

    @ColumnType(typeHandler = PlanStatusHandler.class)
    private PlanStatus status;
    private String remark;//备注
    private Integer creatorId;//创建者 项目人员
    private Integer submitId;//提交者 项目人员
    private Date submitAt;//提交时间
    private String attachment;//附件
    private String attachmentName;//附件
    private String categoryId;//物料大类(一个批次计划只能选一个物料大类的物料)
    private Integer expectNum;//规划数量(一个物料大类的总和)
    private String unit;//单位物料中的多个单位，用分号分隔


    public BatchPlan(
            Integer projectId,
            Integer masterPlanId,
            String masterPlanNo,
            Date deadlineAt,
            String remark,
            Integer creatorId,
            String attachment,
            String attachmentName,
//            PlanStatus status,
            String categoryId,
            Integer expectNum,
            String unit,
            String no
    ) {
        this.no = no;
        this.projectId = projectId;
        this.masterPlanId = masterPlanId;
        this.masterPlanNo = masterPlanNo;
        this.deadlineAt = deadlineAt;
        this.remark = remark;
        this.creatorId = creatorId;
        this.attachment = attachment;
        this.attachmentName = attachmentName;
        this.status = PlanStatus.UnDisposed;
//        if (status.IsSubmitted()){
//            this.submitAt = new Date();
//            this.submitId = creatorId;
//        }

        this.createdAt = new Date();
        this.categoryId = categoryId;
        this.expectNum = expectNum;
        this.unit = unit;
    }

    public BatchPlan() {
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public Date getCreatedAt() {
        return createdAt;
    }


    public void setProjectId(Integer projectId) {
        this.projectId = projectId;
    }

    public Integer getProjectId() {
        return projectId;
    }

    public void setMasterPlanId(Integer masterPlanId) {
        this.masterPlanId = masterPlanId;
    }

    public Integer getMasterPlanId() {
        return masterPlanId;
    }

    public void setDeadlineAt(Date deadlineAt) {
        this.deadlineAt = deadlineAt;
    }

    public Date getDeadlineAt() {
        return deadlineAt;
    }

    public void setStatus(PlanStatus status) {
        this.status = status;
    }

    public PlanStatus getStatus() {
        return status;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getRemark() {
        return remark;
    }

    public void setCreatorId(Integer creatorId) {
        this.creatorId = creatorId;
    }

    public Integer getCreatorId() {
        return creatorId;
    }

    public void setSubmitId(Integer submitId) {
        this.submitId = submitId;
    }

    public Integer getSubmitId() {
        return submitId;
    }

    public void setSubmitAt(Date submitAt) {
        this.submitAt = submitAt;
    }

    public Date getSubmitAt() {
        return submitAt;
    }

    public void setAttachment(String attachment) {
        this.attachment = attachment;
    }

    public String getAttachment() {
        return attachment;
    }


    public boolean canSubmit() {
        return status.IsUnDisposed();
    }

    public boolean canDelete() {
        return status.IsUnDisposed();
    }

    public boolean canCancel() {
        return status.IsSubmitted();
    }

    public boolean canDiscard() {
        return status.IsSubmitted();
    }

    public boolean canEdit() {
        return status.IsUnDisposed();
    }

    public boolean canEnable() {
        return status.IsDiscarded();
    }


    public Integer getExpectNum() {
        return expectNum;
    }

    public void setExpectNum(Integer expectNum) {
        this.expectNum = expectNum;
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }


    public String getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(String categoryId) {
        this.categoryId = categoryId;
    }

    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }


    public String getMasterPlanNo() {
        return masterPlanNo;
    }

    public void setMasterPlanNo(String masterPlanNo) {
        this.masterPlanNo = masterPlanNo;
    }

    public String getAttachmentName() {
        return attachmentName;
    }

    public void setAttachmentName(String attachmentName) {
        this.attachmentName = attachmentName;
    }


}
